﻿using EMS.system.Entityies.WarehouseManagement.SupplierReturnModel;
using EMS.system.IEntityAppService.MasterData.SupplierManagementIService.SupplierManagementDto;
using EMS.system.IEntityAppService.MasterData.SupplierReturnService;
using EMS.system.IEntityAppService.MasterData.SupplierReturnService.SupplierReturnDto;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;

namespace EMS.system.Web.Controllers.MasterData.SupplierReturns
{
    public class SupplierReturnController : Controller
    {
        /// <summary>
        /// 供应商退货服务类
        /// </summary>
        private readonly ISupplierReturnAppService _supplierReturnAppService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="supplierReturnAppService"></param>
        public SupplierReturnController(ISupplierReturnAppService supplierReturnAppService)
        {
            _supplierReturnAppService = supplierReturnAppService;
        }
        /// <summary>
        /// 供应商退货显示视图
        /// </summary>
        /// <returns></returns>
        public IActionResult SupplierReturnList()
        {
            return View();
        }
        /// <summary>
        /// 供应商退货添加视图
        /// </summary>
        /// <returns></returns>
        public IActionResult CreateSupplierReturn()
        {
            return View();
        }
        /// <summary>
        /// 供应商退货更新视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdateSupplierReturn(int id)
        {
            ViewBag.Id = id;
            return View();
        }
        /// <summary>
        /// 获取供应商退货分页 查询 显示
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <param name="returnName"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetSupplierReturnList(int page, int limit, string? returnCode, string? returnName)
        {
            var supplierReturn=await _supplierReturnAppService.GetSupplierReturnList(page, limit,returnCode, returnName);
            return Json(new { code = 0,data=supplierReturn.Queryable,count=supplierReturn.RowCount });
        }
        /// <summary>
        /// 获取供应商管理列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<List<SelectSupplierManagementDto>> GetSupplierManagement()
        {
            return await _supplierReturnAppService.GetSupplierManagement();
           
        }
        /// <summary>
        /// 添加供应商退货
        /// </summary>
        /// <param name="supplierReturnDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> CreateSupplierReturn(SupplierReturnDTO supplierReturnDTO)
        {
            return await _supplierReturnAppService.CreateSupplierReturn(supplierReturnDTO);
        }
        /// <summary>
        /// 删除供应商退货
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<int> DeleteSupplierReturn(string ids)
        {
            return await _supplierReturnAppService.DeleteSupplierReturn(ids);
        }
        /// <summary>
        /// 获取供应商退货主键id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<SupplierReturnDTO> GetSupplierReturnById(int id)
        {
            ViewBag.Id = id;
            return await _supplierReturnAppService.GetSupplierReturnById(id);
        }
        /// <summary>
        /// 更新供应商退货
        /// </summary>
        /// <param name="supplierReturnDTO"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<int> UpdateSupplierReturn(SupplierReturnDTO supplierReturnDTO)
        {
            return await _supplierReturnAppService.UpdateSupplierReturn(supplierReturnDTO);
        }
    }
}
